<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<!DOCTYPE html>
<html>
<head>
    <title>

    </title>
</head>

<body>

<div id="wrapper">
    <div class="gray-bg">
        <div class="row m-t-sm">
        </div>
        <div class="wrapper wrapper-content animated fadeInRight">
            <div class="row">
                <div class="col-lg-12">
                    <div class="ibox float-e-margins">
                        <div class="ibox-content">
                                <input  type="hidden" id="teamId" name="teamId" value="${teamId}"/>
                                <input  type="hidden" id="signId" name="signId" value="${signId}"/>
                                <input  type="hidden" id="ecn" name="ecn" value="${ecn}"/>

                                <div class="form-group">
                                    <p>团队服务包</p>
                                    <div class="table-responsive">
                                        <table class="table table-striped table-bordered  table-hover m-b-sm" id="item-table">
                                            <thead>
                                                <tr>
                                                    <th width="14%">服务包名称</th>
                                                    <th width="12%">支付方式</th>
                                                    <th width="12%">服务项数量</th>
                                                    <th width="42%">描述</th>
                                                    <th width="10%">价格（元）</th>
                                                    <th width="10%">操作</th>
                                                </tr>
                                            </thead>
                                        </table>
                                    </div>
                                </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

    </div>
</div>
<script src="${ctx}/static/inspinia/js/plugins/layer/layer.js"></script>
<script src="${ctx}/static/inspinia/js/jquery-2.1.1.js"></script>
<script>
    var signIds;
    var ecns;
    var teamIds;
    $(document).ready(function() {
        signIds = '${signId}';
        ecns = '${ecn}';
        teamIds = '${teamId}';
        var spcklist = JSON.parse('${data}');
        if (spcklist.length > 0){
            for (i in spcklist) {
                addItem(spcklist[i].id , spcklist[i].title , spcklist[i].payType , spcklist[i].count , spcklist[i].memo , spcklist[i].price,spcklist[i].hasChosen );
            }
        }
    });

    function addItem(id,title,payType,count, memo, price ,hasChosen) {
        var model = $(
            "<tr>" +
            "<td>" + title + "</td>" +
            "<td>" + getGender(payType) + "</td>" +
            "<td><a onclick='showcount(" + id + " );'>"+count+"</a></td>" +
            "<td>" + memo + "</td>"+
            "<td>" + price + "</td>"
        );
        model.append("<td><a onclick='save_itemss(" + id +" );'>添加</a></td></tr>");
        $("#item-table").append(model);
        return true;
    }

    function getGender(code){
        if(code == 1){
            return "公卫";
        }else if(code == 2){
            return "医保";
        }else if(code == 3){
            return "自费";
        }else {
            return "";
        }
    }

    /*function save_item(id ) {
        $.ajax({
            method: "POST",
            url: "${ctx}/medical/sign/spck/add",
            data: {
                teamId:teamIds,
                ecn:ecns,
                packageIdList:id,
                signId:signIds

            },
            dataType: "json",
            async: false,
            success: function(response) {
                if (response.code == 0) {
                    layer.alert('服务包添加成功');
                    var data = response.data;
                    parent.frames[0].addspckItem(id ,data.title,data.payType,data.count,data.memo, data.price , response.time);
                    //window.location.href="${ctx}/medical/sign/spck/team/list?teamId=${teamId}&ecn=${ecn}&signId=${signId}";
                }else{
                    layer.alert('添加错误');
                }
            }
        });
    }

    function save_items(id) {
        layer.confirm('已存在相同服务包，是否重复添加？', {
            btn: ['确定','取消'] //按钮
        }, function(){
            $.ajax({
                method: "POST",
                url: "${ctx}/medical/sign/spck/add",
                data: {
                    teamId:teamIds,
                    ecn:ecns,
                    packageIdList:id,
                    signId:signIds

                },
                dataType: "json",
                async: false,
                success: function(response) {
                    if (response.code == 0) {
                        layer.alert('服务包添加成功');
                        var data = response.data;
                        parent.frames[0].addspckItem(id ,data.title,data.payType,data.count,data.memo, data.price , response.time);
                    }else{
                        layer.alert('添加错误');
                    }
                }
            });
        }, function(){

        });
    }*/

    function save_itemss(id ) {
        $.ajax({
            method: "POST",
            url: "${ctx}/medical/sign/spck/readd",
            data: {
                teamId:teamIds,
                ecn:ecns,
                packageIdList:id,
                signId:signIds

            },
            dataType: "json",
            async: false,
            success: function(response) {
                if (response.code == 0) {
                    layer.confirm('已存在相同服务包，是否重复添加？', {
                        btn: ['确定','取消'] //按钮
                    }, function(){
                        $.ajax({
                            method: "POST",
                            url: "${ctx}/medical/sign/spck/add",
                            data: {
                                teamId:teamIds,
                                ecn:ecns,
                                packageIdList:id,
                                signId:signIds

                            },
                            dataType: "json",
                            async: false,
                            success: function(response) {
                                if (response.code == 0) {
                                    layer.alert('服务包添加成功');
                                    var data = response.data;
                                    parent.frames[0].addspckItem(id ,data.title,data.payType,data.count,data.memo, data.price , response.time,response.prid);
                                }else{
                                    layer.alert('添加错误');
                                }
                            }
                        });
                    }, function(){

                    });
                }else{
                    $.ajax({
                        method: "POST",
                        url: "${ctx}/medical/sign/spck/add",
                        data: {
                            teamId:teamIds,
                            ecn:ecns,
                            packageIdList:id,
                            signId:signIds

                        },
                        dataType: "json",
                        async: false,
                        success: function(response) {
                            if (response.code == 0) {
                                layer.alert('服务包添加成功');
                                var data = response.data;
                                parent.frames[0].addspckItem(id ,data.title,data.payType,data.count,data.memo, data.price , response.time);
                                //window.location.href="${ctx}/medical/sign/spck/team/list?teamId=${teamId}&ecn=${ecn}&signId=${signId}";
                            }else{
                                layer.alert('添加错误');
                            }
                        }
                    });
                }
            }
        });
    }


    function showcount(spckid) {
        parent.layer.open({
            type: 2,
            title: '查看服务项',
            shadeClose: true,
            shade: 0.8,
            area: ['1000px', '480px'],
            content: '${ctx}/medical/sign/spck/item/list?teamIds=${teamId}&ecn=${ecn}&spckId='+spckid
        });
    }
    
</script>
</body>
</html>
